#include <stdio.h>
int lower(int c){
    if (c>='A' && c<='Z')
        return c-'A'+'a';
    else
        return c;
}

int htoi(char s[]){
    int answer=0;
    int error=1;
    int i=0;
    if(s[i]=='0'){
        i++;
        if(s[i]=='x' || s[i]=='X'){
            error=0;
            i++;
        }
    }

    while(error==0 && s[i] !='\0'){
        answer = answer*16;
        if(s[i] >= '0' && s[i] <= '9')
            answer+=s[i]-'0';
        else if(s[i] >= 'a' && s[i] <='f')
            answer+=s[i]-'a'+10;
        else if(s[i] >= 'A' && s[i] <='Z')
            answer+=s[i]-'A'+10;
        else
            error=1;
    i++;
    }
    if(error==1)
        answer=0;
    return answer;
}

int main(){
//    printf("C change to lower case is: %c\n",lower('C'));

    printf("0xFE is equal: %d\n",htoi("0xFE"));
    printf("0X10 is equal: %d\n",htoi("0X10"));
    printf("0x0e is equal: %d\n",htoi("0x0e"));
    printf("F00 is equal: %d\n",htoi("F00"));
    printf("bar is equal: %d\n",htoi("bar"));
    printf("0100 is equal: %d\n",htoi("0100"));
    printf("0x1 is equal: %d\n",htoi("0x1"));
    printf("0xA is equal: %d\n",htoi("0xA"));
    printf("0X0C0BE is equal: %d\n",htoi("0X0C0BE"));
    printf("abcdef is equal: %d\n",htoi("abcdef"));
    printf("123456 is equal: %d\n",htoi("123456"));
    printf("0x123456 is equal: %d\n",htoi("0x123456"));
    printf("deadbeef is equal: %d\n",htoi("deadbeef"));
    printf("zog_c is equal: %d\n",htoi("zog_c"));
    return 0;
}
